#@laybase() 
#define main()

#@orderProgress()
<div class="modal fade" tabindex="-1" role="dialog" aria-labelledby="zlbcDialog" id="zlbcDialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header" style="padding: 10px;">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h4 class="modal-title" id="">选择需要补充的资料</h4>
      </div>
      <div class="modal-body"></div>
      <div class="modal-footer">
        <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
        <button type="button" class="btn btn-primary submit" data-dismiss="modal" data-loading-text="请稍后...">提交</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<div style="margin-top: 15px;overflow: hidden;">
	<div class="col-md-3">
	#setLocal(tabs=["-","运营商","产品","日期","姓名","进度"])
	#setLocal(attrs=["owner","Operator","product","date","name","step"])
	#@dataTable(tabs,attrs,orderList,"/admin/photoReview")
	</div>
	#@datashowbox()
	<div class="col-md-7">
		<div style="display: none;" id="databox">
			<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#zlbcDialog">资料补充清单</button>
			<div style="display: table; width: auto; margin-left: auto; margin-right: auto;">
				#@picview()
			</div>
		</div>
	</div>
	<div class="col-md-2 scrollbox">
		<ul	class="nav well" id="nav-pills">
		</ul>
	</div>
</div>
<script>
	var $imgview = $('#imgview')
	var $source = $('#img_0')
	var $review = $('#review')
	var $iname = $('#iname label')[0]
	var curTarget;
	var lastSonbox = null;

	function upDateImg(src,name,state,err){
		//loading动画
		$imgview.children(".loading").show()
		$("input1").hide()
		$source.html("")
		var image = new Image(),
			maxW = $imgview.width(),
			maxH = $imgview.height(),
			imgDom = $("<img />")
		image.src = src
		image.onload = function(){
			var dom = $("<div class='imgbox'></div>")
			dom.css({
				width: $imgview.width(),
				height: $imgview.height()
			})
			dom.iviewer({
                src: src
            });
			$imgview.children(".imgbox").remove()
			$imgview.append(dom)
			$imgview.children(".loading").hide()
		}
		
		image.onerror = function(){
			$imgview.children(".imgbox").remove()
			$imgview.children(".loading").hide()
			_x.show_alert_sh("图片找不到！",false)
		}
		$review.attr("display","none")
		$review.attr("name",name)
		$review.val(err)
	}
	$("#btn2,#input1 .cl").on("click",function(){
		if(#("input1").style.display=="none"){
			#("input1").style.display=""
		}else{
			#("input1").style.display="none"
		}
	})
	function select(target) {
		if(!target)return;
		curTarget = target
		var newsrc = target.dataset.src
		var name = target.name
		var exp = target.dataset.exp
		var state = target.dataset.state
		var err = target.dataset.err
		//最后一个显示审核通过按钮
		if($(target).parents("li").index() == $(target).parents("ul").children().length - 1 && $(target).index() == $(target).parent().children().length - 1){
			$("#tongguo").show();
		}else{
			$("#tongguo").hide();
		}
		$iname.innerText=exp +"-"+ $(target).text()
		upDateImg(newsrc,name,state,err)
	}
	function updateState(state){
		if (state!=null) {
			$("#err").css("display","none")
			$("#ok").css("display","none")
			if (state=="5") {
				$("#ok").css("display","")
			}else if (state=="3"||state.length>1) {
				$("#err").css("display","")
			}
		}
	}
	function submitMsg(type,btn){
		if(type == 1){
			if(_x.isEmpty($review.val())){
				$review.attr("placeholder","请输入反馈内容！").focus()
				return
			}
		}
		$(btn).button('loading')
		// jquery 表单提交 
		var dataObj = {paramterName:$review.attr("name")};
		if (type == 0) {
			dataObj.state = "5"
		}else{
			dataObj.state = "3"
			dataObj.err = $review.val()
		}
		 $.ajax({
	           type: "POST",
	           url: "/admin/supplyMsg",
	           data: dataObj,
	           success: function(data){
		            if (data.code==1){
			             #("input1").style.display="none"
			             curTarget.dataset.state = dataObj.state
			             if(dataObj.err&&dataObj.err.length>0){
			            	 curTarget.dataset.err = dataObj.err
			             }
			             freshState(curTarget)
			             showNextCollapse($(curTarget))
			             _x.show_alert_sh(data.msg,true)
					}else{
						_x.show_alert_sh(data.msg,false)
					}
		            $(btn).button('reset')
	           },
	           error:function(){
	        	   _x.show_alert_sh("您的网络异常，请稍后重试！",false)
	        	   $(btn).button('reset')
	           }
	        })
		return false
	}
	
	function showNextCollapse(curTarget){
		var nextA = curTarget.next("a");
		curTarget.removeClass("active");
		if(nextA.length < 1){//如果是最后一个
			curTarget.parent().addClass("hide");
			nextA = curTarget.parents("li").next("li");
			if(_x.isEmpty(nextA)){
				return;
			}
			nextA = nextA.children(".sonbox").removeClass("hide").children("a").eq(0);
			lastSonbox = nextA.parent();
		}
		nextA.addClass("active");
		select(nextA[0]);
	}
	
	function freshState(target){
		var str = "";
		var flg = 0
		$daddy = $(target).parents("li").find("p")
		if (target.dataset.state=="5") {
			str = str+"<span class='glyphicon glyphicon-ok' "+
			"style='color:#00cc33'></span>"+target.innerText
			target.innerHTML = str
			flg = 2
			var mark = true
			$(target).siblings("a").each(function(){
				if($(this)[0].dataset.state != "5"){
					mark = false
					return false
				}
			})
			if(mark){
				$daddy.html("<span class='glyphicon glyphicon-ok' "+
					"style='color:#00cc33'></span>"+$daddy.text())
			}
		}else if(target.dataset.state=="3") {
			str = str+"<span class='glyphicon glyphicon-info-sign' "+
			"style='color:#f0ad4e'></span>"+target.innerText
			target.innerHTML = str
			flg = 1
			$daddy.html("<span class='glyphicon glyphicon-info-sign' "+
					"style='color:#f0ad4e'></span>"+$daddy.text())
		}
		
	}
	$(function(){
		var ulnav = $("#nav-pills"),
			datashowbox = $("#datashowbox"),//数据统计
			databox = $("#databox"),//数据展示层
			zlbcList = $("#zlbcDialog");//资料补充弹框
		/*datashowbox.find("select").change(function(){
			var orderId = $(this).val();
			$.getJSON("/admin/getJson",{type:1,orderId:orderId},function(data){
				datashowbox.hide();
				databox.show();
		    	getBaseTab(data,showSuc)
		    	
		    	//默认展开第一张
		    	var nowSon = ulnav.children("li").eq(0).children(".sonbox").removeClass("hide"),
		    		aDom = nowSon.children("a").eq(0).addClass("active");
		    	nowSon.removeClass("hide");
				lastSonbox = nowSon;
				select(aDom[0]);
			})
		})*/
		

		function getJson(type,orderId){
			var params = {
				params: {
					type:type,
					orderId:orderId
				}
			}
			return axios.get("/admin/getJson",params)
		}
		
		function getSupply(orderId){
			return axios.get("/admin/supplySelectInfo/" + orderId)
		}
			
		$("#rtable").on("click","tbody tr",function(){
			if($(this).hasClass("sel"))return;
			var orderId = $(this).data("orderid");
			$(this).addClass("sel").siblings("tr").removeClass("sel");
			$("#err,#ok").hide();
			$("#img0").attr("src","").siblings("img").remove();
			
			axios.all([getJson(9,orderId),getJson(7,orderId),getSupply(orderId)])
			.then(axios.spread(function(json1,json2,supply){
				console.log(json1.data)
				getBaseTab(json1.data,showSuc)
		    	
		    	//默认展开第一张
		    	var nowSon = ulnav.children("li").eq(0).children(".sonbox").removeClass("hide"),
		    		aDom = nowSon.children("a").eq(0).addClass("active");
		    	nowSon.removeClass("hide");
				lastSonbox = nowSon;
				select(aDom[0]);
				
				
				console.log(supply.data)
		    	datashowbox.hide();
				databox.show();
				detailedList(supply.data)
				_com.addMsg(databox,json2.data)

				axios.get("/admin/getAllStates")
				.then(function(progress){
					_com.renderOrderProgress(progress.data)
				})
			}))
		})
		
		//渲染资料清单
		function detailedList(data){
			var html = "";				
			for(var i = 0;i < data.length;i++){
				var checked = ""
				if(data[i].selected)checked = "checked='true'"
				html += "<label class='checkbox-inline' style='display: block;margin-left: 10px;margin-bottom: 8px;'>"+
				  		"	<input type='checkbox' "+ checked +" value='"+ data[i].paramterName +"'> "+ data[i].zhExpl +""+
						"</label>";
			}
			zlbcList.find(".modal-body").html(html);
		}
		
		zlbcList.find("button.submit").click(function(){
			var $btn = $(this).button('loading')
			var json = {};			
			zlbcList.find("input").each(function(){
				if($(this)[0].checked){
					json[$(this).val()] = true;
				}else{
					json[$(this).val()] = false;
				}
			})
			console.log(json)
			/*$.getJSON("/admin/submitSupplyPara",json,function(data){
				console.log(data)
			})*/
			var params = {
				params: json
			}
			axios.get("/admin/submitSupplyPara",params)
			.then(function(res){
				if(res.data.code == 1){
					_x.show_alert_sh(res.data.msg,true)
				}else{
					_x.show_alert_sh(res.data.msg,false)
				}
				$btn.button('reset')
			})
			.catch(function(){
				_x.show_alert_sh("您的网络异常，请稍后重试！",false)
				$btn.button('reset')
			})
		})
		
		
		//数据渲染完毕做处理
		function showSuc(){
			ulnav.children("li").each(function(){
				var mark = -1,
					mark2 = true;
				$(this).find("a").each(function(){
					var state = $(this).data("state");
					if(state == "3"){//有反馈
						mark = false;
						return false;
					}else if(state == "5"){//通过
						mark = true;
					}else{//其他
						mark = -1;
						mark2 = false;
					}
				})
				if(mark === true && mark2 == true){
					$(this).children("p").prepend("<span class='glyphicon glyphicon-ok' style='color:#00cc33'></span>");
				}else if(mark === false){
					$(this).children("p").prepend("<span class='glyphicon glyphicon-info-sign' style='color:#f0ad4e'></span>");
				}
			})
		}
		
		function getBaseTab(data,callback){
			var html = "";
			
			for(var i = 0;i < data.length;i++){
				html += "<li><p>"+ data[i].zhExpl +"</p>";
				var that = data[i],
					pathArr = that.path,
					errs = [],
					sonbox = "<div class='sonbox hide'>";
				if(data[i].err)errs = data[i].err;
				if(!that.path || !that.state){//测试完成后删除判断
					break;	
				
					for(var j = 0;j < pathArr.length;j++){
						var err = "";
						if(errs.length > j){
							err = errs[j];
						}
						sonbox += "<a name='" +that.paramterName+"_"+ (j + 1) + "' href='javascript:;' data-state='"+ that.state[j] +"' data-src='"+ pathArr[j] +"' data-exp='" +that.zhExpl+ "' data-err='"+ err +"'>"+ (j + 1) +"</a>";
					}
				}else{
					for(var j = 0;j < pathArr.length;j++){
						var state = that.state[j],
							span = "",
							err = "";
						if(errs.length > j){
							err = errs[j];
						}
						if(state == 3){//重新上传
							span = "<span class='glyphicon glyphicon-info-sign' style='color:#f0ad4e'></span>";
						}else if(state == 4){//重新上传完毕
							span = "<span class='glyphicon glyphicon-info-sign' style='color:#f0ad4e'></span>";
						}else if(state == 5){//审核通过
							span = "<span class='glyphicon glyphicon-ok' style='color:#00cc33'></span>";
						}
						sonbox += "<a name='" +that.paramterName+"_"+ (j + 1) + "' href='javascript:;' data-state='"+ state +"' data-src='"+ pathArr[j] +"' data-exp='" +that.zhExpl+ "' data-err='"+ err +"'>"+ span + (j + 1) +"</a>";
					}
					
				}
				sonbox += "</div>";
				html += sonbox + "</li>";
			}
			ulnav.html(html);
			if(data.length == ulnav.children("li").length){
	        	callback();
	        }
		}
		
		//点击展开
		$("#nav-pills").on("click","li p",function(){
			var that = $(this);
			if(that.siblings(".sonbox").hasClass("hide")){
				var nowSon = that.siblings(".sonbox");
				nowSon.removeClass("hide");
				if(lastSonbox && lastSonbox != nowSon){
					lastSonbox.addClass("hide");
				}
				lastSonbox = nowSon;
			}else{
				that.siblings(".sonbox").addClass("hide");
				lastSonbox = null;
			}
		})
		
		//显示图片
		var lastA = null;
		$("#nav-pills").on("click","li .sonbox a",function(){
			var that = $(this);
			//最后一个显示审核通过按钮
			if(that.parents("li").index() == that.parents("ul").children().length - 1 && that.index() == that.parent().children().length - 1){
				$("#tongguo").show();
			}else{
				$("#tongguo").hide();
			}
			if(lastA)lastA.removeClass("active");
			that.addClass("active").siblings("a").removeClass("active");
			select(that[0]);
			lastA = that;
		})
		
		function showNextCollapse(){
			if(index==null){
				index=0
			}else{
				index++
			}
			preOnload(index, index+5)
			var elm = targetArr[index]
			elm.click()
			function floor(el,action){
				if (el.hash!=null) {
					$(el.hash).collapse(action)
					floor($(el.hash))
				}else{
					el.click()
				}
			}
			floor(elm,"show")
		}
		function preOnload(idxStart,idxEnd){
			for (var i = idxStart; i <= idxEnd; i++) {
				if (imgArr[i]!=null&&imgArr[i]!="") {
					var img = new Image()
					img.src = imgArr[i]
				}
			}
		}
		
		//审核通过
		$("#btn3").click(function(){
			var $btn = $(this).button('loading')
			axios.get("/admin/supplyFinished")
			.then(function(res){
				if(res.data.code == "1"){
					_x.show_alert_submit(res.data.msg,true)
				}else{
					_x.show_alert_submit(res.data.msg,false)
				}
				$btn.button('reset')
			})
			.catch(function(){
				$btn.button('reset')
				_x.show_alert_submit("您的网络异常，请稍后重试！",false)
			})
		});
	})
</script>
#end
